﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Globalization;

namespace ConsoleApplication1
{
    class Patient
    {
        public int id;
        public string name;
        public string surname;
        public string patronymic;
        public DateTime dob;


        public string toDbFormat()
        {
            return id + "," + name + "," + surname + "," + patronymic + "," + dob.ToString("dd-MM-yyyy");
        }


        public static Patient parseFromDb(String s)
        {
            string[] ar = s.Split(',');
            return parseFromStringArray(ar);
        }

        public static Patient parseFromStringArray(string[] ar)
        {
            Patient p = new Patient();
            if (ar[0] != null)
            {
                p.id = Convert.ToInt32(ar[0]);
            }
            p.name = ar[1];
            p.surname = ar[2];
            p.patronymic = ar[3];

            DateTime dt;
            if (DateTime.TryParseExact(ar[4], "dd-MM-yyyy", null, DateTimeStyles.None, out dt))
            {
                p.dob = dt;
            }

            return p;
        }
    }

}